package com.dongdong.zhuangji.utils;

/**
 * @author dongdong 抖音号：W13883155245
 * @version 1.0
 * @date 2025/5/6
 * @description 桩基收方单图片生成器
 */
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class GenerateImage {
    public static void main(String[] args) {
        // 假设分辨率为 72 dpi（每英寸点数），1 英寸 = 2.54 厘米
        double dpi = 72;
        int width = (int) (16.25 / 2.54 * dpi);
        int height = (int) (16.7 / 2.54 * dpi);

        // 创建 BufferedImage 对象
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = image.createGraphics();

        // 设置背景颜色为白色
        g2d.setColor(Color.WHITE);
        g2d.fillRect(0, 0, width, height);

        // 设置绘图颜色为黑色
        g2d.setColor(Color.BLACK);

        // 绘制长方形
        int rectX = 50;
        int rectY = 50;
        int rectWidth = 200;
        int rectHeight = 150;
        g2d.drawRect(rectX, rectY, rectWidth, rectHeight);

        // 绘制直线
        int lineX1 = 100;
        int lineY1 = 250;
        int lineX2 = 300;
        int lineY2 = 250;
        g2d.drawLine(lineX1, lineY1, lineX2, lineY2);

        // 绘制圆
        int circleX = 300;
        int circleY = 50;
        int circleRadius = 75;
        g2d.drawOval(circleX, circleY, 2 * circleRadius, 2 * circleRadius);

        // 绘制文字
        g2d.setFont(new Font("Arial", Font.PLAIN, 24));
        String text = "Hello, Java Graphics!";
        int textX = 50;
        int textY = 400;
        g2d.drawString(text, textX, textY);

        // 释放图形上下文
        g2d.dispose();

        // 保存图片
        try {
            File output = new File("generated_image.png");
            ImageIO.write(image, "png", output);
            System.out.println("图片已生成：generated_image.png");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}